package org.zjx.action.route;

import org.zjx.action.Action;
import org.zjx.action.basic.DelayAction;
import org.zjx.action.basic.HotkeyAction;
import org.zjx.action.basic.ScreenshotAction;
import org.zjx.action.game.GameAction;
import org.zjx.core.IWindow;
import org.zjx.entity.Address;

import java.awt.event.KeyEvent;

public class BackToSectAction extends Action {
    private final Address targetAddress;

    public BackToSectAction(IWindow targetWindow, Address targetAddress) {
        super(targetWindow, false);
        this.targetAddress = targetAddress;
    }

    @Override
    protected void doExecute() throws Exception {
        while (!getAddressNow().near(targetAddress,5)) {
            new HotkeyAction(targetWindow, KeyEvent.VK_F8).execute();
            new DelayAction(targetWindow, 1000).execute();
        }
    }

    public Address getAddressNow() {
        new ScreenshotAction(targetWindow).execute();
        new GameAction(targetWindow).execute();
        return targetWindow.getState().getGameState().getAddress();
    }
}
